#  Copyright (c) 2020 - ~, WANGXI
#  
#  SIMPLE TCP TCPTEST TCL FILE
#  Used in NS-2 simulator
#  Clone from https://gitee.com/WangXi_Chn/ns2_modulelib
#  Note in https://www.yuque.com/wangxi_chn/kozrfl
#  
#  Change Logs:
#  Date           Author       Notes			Mail
#  2020-11-24     WangXi   	   first version	WangXi_Chn@foxmail.com

# Bulid a simulator class example,any exampel name is fine
set ns [new Simulator]

# Open a file named out.tr and use it to record the tract data within modulation
# Virable tf1 point to the file
set tf1 [open out.tr w]
$ns trace-all $tf1

set nf1 [open out.nam w]
$ns namtrace-all $nf1

# Build a process named finish used to close two file
# And refer to nam.exe
# Refresh all traces' buffer within modulation
proc finish {} {
    global ns tf1 nf1
    $ns flush-trace
    close $tf1
    close $nf1
    exec nam out.nam &
    exit 0
}

# Define node
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]

# Define link
#   direction   node    band    delay   queue-type
$ns duplex-link $n0 $n1 1Mb     5ms     DropTail
$ns queue-limit $n0 $n1 20
$ns duplex-link $n1 $n2 2Mb     5ms     DropTail
$ns queue-limit $n1 $n2 20

# Define protacol
set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n2 $sink
$ns connect $tcp $sink

# Define application
set ftp [new Application/FTP]
$ftp attach-agent $tcp

$ns at 0.5 "$ftp start"
$ns at 4.5 "$ftp stop"
$ns at 5 "finish"
$ns run

#/************************ (C) COPYRIGHT 2020 WANGXI **************END OF FILE****/
